Skip to content

feat(cli): abbreviate large pasted text and optimize paste performance#4916

Merged
marius-kilocode merged 5 commits intomainfrom
cli-bracketed-paste
Jan 13, 2026
Merged

feat(cli): abbreviate large pasted text and optimize paste performance#4916
marius-kilocode merged 5 commits intomainfrom
cli-bracketed-paste

Conversation

@marius-kilocode
Copy link
Collaborator

@marius-kilocode marius-kilocode commented Jan 9, 2026

Summary

  • Abbreviate large pasted text (10+ lines) as [Pasted text #N +X lines] to prevent input field overflow when pasting logs or large code blocks
  • Fix paste performance by skipping unnecessary clipboard image checks for bracketed pastes

Changes

  • Add processPastedText.ts utilities for handling pasted text references (extract, remove, expand)
  • Add pasted text reference atoms in keyboard.ts with handlePaste function
  • Expand references to full content in useMessageHandler.ts before sending messages
  • Optimize KeyboardProvider.tsx to skip osascript clipboard check for bracketed pastes
  • Permance is optimized, just takes a few ms for a very large text

How it works

  • Pastes with 10+ lines are stored and displayed as [Pasted text #1 +X lines]
  • References are expanded to full content when the message is submitted
  • Image pasting via Cmd+V still works (clipboard check only runs for explicit Cmd+V)
  • Regular terminal paste (bracketed paste mode) is now instant
image

@changeset-bot
Copy link

changeset-bot bot commented Jan 9, 2026

🦋 Changeset detected

Latest commit: 23b2132

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@marius-kilocode marius-kilocode requested a review from a team January 9, 2026 22:36
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Jan 9, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR adds a feature to abbreviate large pasted text in the CLI input field. When users paste text with 10+ lines, it displays as [Pasted text #N +X lines] instead of the full content, preventing input field overflow. The full text is stored in a reference map and expanded when the message is sent.

Key Changes:

  • New processPastedText.ts module with regex matching and text expansion utilities
  • Pasted text reference atoms in keyboard.ts for state management
  • Integration in useMessageHandler.ts to expand references before sending
  • Simplified KeyboardProvider.tsx by removing unused paste buffer atoms
  • Comprehensive test coverage for all new functionality

Code Quality:

  • Clean separation of concerns between storage, display, and expansion
  • Proper handling of edge cases (threshold boundary, tab normalization)
  • Good test coverage including unit tests for atoms and helper functions
  • Follows existing patterns in the codebase (similar to image reference handling)
Files Reviewed (6 files)
  • .changeset/abbreviate-large-pasted-text.md - Changeset for CLI minor version bump
  • cli/src/media/processPastedText.ts - New helper functions for pasted text references
  • cli/src/media/__tests__/processPastedText.test.ts - Tests for processPastedText helpers
  • cli/src/state/atoms/keyboard.ts - New atoms for pasted text reference management
  • cli/src/state/atoms/__tests__/keyboard.test.ts - Tests for paste abbreviation behavior
  • cli/src/state/hooks/useMessageHandler.ts - Integration to expand references on send
  • cli/src/ui/providers/KeyboardProvider.tsx - Simplified paste handling

@@ -0,0 +1,28 @@
// Regex to match pasted text references: [Pasted text #N +X lines]
export const PASTED_TEXT_REFERENCE_REGEX = /\[Pasted text #(\d+) \+(\d+) lines\]/g
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok for now, but a much better approach for the future, in my opinion, would be to refactor the input field to be an array of objects, for example:

type PasteItem = {
  type: "paste";
  text: string;
}

type ImageItem = {
  type: "image";
  pathToFile: string;
}

type StringItem = {
  type: "string";
  value: string;
}

type InputFieldValue = PasteItem | ImageItem | StringItem;

type InputFieldState = InputFieldValue[];

// then, in the component
const [inputFieldState, setInputFieldState] = useState<InputFieldState>([]);

// refactor the renderer to correctly render input field state
function render(state: InputFieldState): string

// refactor state updaters to correctly handle the new shape
function handleX(cursorPosition: number, event: unknown): InputFieldState

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking back at this, I agree. This is the better approach. I will get a follow up done.

@marius-kilocode marius-kilocode merged commit f02364c into main Jan 13, 2026
12 checks passed
@marius-kilocode marius-kilocode deleted the cli-bracketed-paste branch January 13, 2026 13:56
Drilmo pushed a commit to Drilmo/kilocode that referenced this pull request Jan 16, 2026
VSCode terminal sends empty bracketed paste sequences for Cmd+V,
unlike regular terminals that send key events directly. This was
broken in Kilo-Org#4916 when the condition changed to skip empty pastes.

Now we check the clipboard for images when receiving an empty
bracketed paste, restoring the behavior from Kilo-Org#4832.
marius-kilocode pushed a commit that referenced this pull request Jan 16, 2026
VSCode terminal sends empty bracketed paste sequences for Cmd+V,
unlike regular terminals that send key events directly. This was
broken in #4916 when the condition changed to skip empty pastes.

Now we check the clipboard for images when receiving an empty
bracketed paste, restoring the behavior from #4832.

Co-authored-by: Jérémy Beutin <jeremybeutin@MacBook-Pro-de-Jeremy.local>
@github-actions github-actions bot mentioned this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI Kilo Code CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy/paste multilines does not pass instructions as a block

2 participants